package com.fragment.demo;

import baidumapsdk.demo.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class BaseActivity extends FragmentActivity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		test5();
	}
	
	public TitleBarView tbv;
	public LinearLayout mv;

	public void test5() {
		setContentView(R.layout.layout_base);
		tbv = ((TitleBarView) findViewById(R.id.layout_titlebar));
		mv = ((LinearLayout) findViewById(R.id.layout_mainview));
	}
	public void set(View.OnClickListener paramOnClickListener){
		ImageView localImageView = new ImageView(this);
		localImageView.setImageResource(R.drawable.ic_back);
		
		tbv.a(localImageView,new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Toast.makeText(BaseActivity.this, "ni hao", Toast.LENGTH_SHORT).show();
				getSupportFragmentManager().popBackStack();
			}
		});
	}
	 public void addMainView(View paramView)
	  {
	    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-1, -1);
	    localLayoutParams.weight = 1.0F;
	    mv.addView(paramView, localLayoutParams);
	  }
	 
	 public void addMainFragment(Fragment fragment){
			FragmentManager fm = getSupportFragmentManager();
			FragmentTransaction ft = fm.beginTransaction();
	
			ft.add(R.id.layout_mainview, fragment);
			ft.commit();

	 }
	 public void replaceMainFragment(Fragment fragment){
			FragmentManager fm = getSupportFragmentManager();
			FragmentTransaction ft = fm.beginTransaction();

			ft.replace(R.id.layout_mainview, fragment);
			ft.addToBackStack(null);
			ft.commit();
	 }
}
